package Main;

import java.io.File;
import java.sql.SQLException;
import java.util.List;

import AnalysisRpm.rpmOpera;
import dbConn.DBconn;

public class rpmThread implements Runnable{ // 实现Runnable接口
    public void run()
    {  // 覆写run()方法
        System.out.println("rpmThread stared...");
		String rpmFile = "/Users/xianglin/lynnxiang/testPrj/test_Rpm";
		partRpmtest(rpmFile);
    }
    
	public static void partRpmtest(String rpmFilePath)
	{
		File src = new File(rpmFilePath);
		List<File> files = rpmOpera.searchFiles(src, "rpm");
		String cmd = "";
		String strPath = "";
		String rpmStr_qpi = "";
		String rpmStr_qpR = "";
		
		if(files.size() > 0)
		{
			for(File file : files)
			{
				strPath = String.valueOf(file);
				cmd = rpmOpera.combineCmd_qpi(strPath);
				rpmStr_qpi = rpmOpera.exeCmd(cmd);
				
				cmd = rpmOpera.combineCmd_qpR(strPath);
				rpmStr_qpR = rpmOpera.exeCmd(cmd);
				
				try
				{
					//dbConn.DBconn rpmOper = new dbConn.DBconn();
					//DBconn.init();
					DBconn.setRpmInfo(rpmStr_qpi, rpmStr_qpR, strPath);
					DBconn.getLastOneInfo();
					//dbConn.DBconn.closeConn();
				}
				catch (SQLException e) 
		        {
		            e.printStackTrace();
		        }
			}
		}
		else
		{
			System.out.println("Error! Without RPM Package!");
		}
	}
};

